package com.vue.vuedemo.Controller;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.vue.vuedemo.pojo.Personsplayers;
import com.vue.vuedemo.pojo.Personsteams;
import com.vue.vuedemo.service.PersonPlayersService;
import com.vue.vuedemo.service.PersonsTeamsService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;
import java.util.List;

@RestController
@JsonIgnoreProperties({"hibernateLazyInitializer","handler"})
@CrossOrigin(origins = {"http://localhost:8080"}) //当前网站向另一个网站请求数据就是跨域
@Controller
public class PersonPlayersController {
    @Resource
    private PersonPlayersService personPlayersService;

    //根据人员编号查询人员与球员信息
    @GetMapping(value = "personsPlayersFindAll")
    public List<Personsplayers> findAll(Integer ppPid, HttpSession session){
        //         ppPid = (Integer) session.getAttribute("userId");
//        ppPid = 1;
        List<Personsplayers> list =  personPlayersService.findShow(ppPid);
        return list;
    }

    public Integer num;
    //人员喜欢的游戏表添加
    @GetMapping(value = "personsPlayersAdd")
    public Integer add(Integer ppPid, Integer ppTId, Personsplayers personsplayers, HttpSession session){
//         pTpId = (Integer) session.getAttribute("userId");
//        ppPid = 1;
        if(personPlayersService.Ppidshow(ppPid, ppTId) == null || personPlayersService.Ppidshow(ppPid, ppTId).equals("")){
            try {
                personsplayers.setPpPid(ppPid);
                personsplayers.setPpTId(ppTId);
                personPlayersService.addPP(personsplayers);
                num = 1; //成功
            }catch (Exception ex){
                num = 2; //失败
            }
        }else{
            num = 3;
        }
        return num;
    }

    //人员喜欢的游戏表删除
    @GetMapping(value = "personsPlayersDel")
    public Integer del(Integer ppId){
        try {
            personPlayersService.delPP(ppId);
            num = 1; //成功
        }catch (Exception ex){
            num = 2; //失败
        }
        return num;
    }


}
